
const inform={
    drinks:{"可乐":4,"雪碧":7,"精华":15,"橙汁":8},
    foods:{"薯片":6,"蛋糕":20,"烤饼":9,"肉干":12},
    books:{"教科书":444,"小说":666,"漫画":111}
}
const userList=[]//{a,b,c}
function searchGoods(type,min,max){
    var arr=[];//返回数组
    var max=parseInt(max);
    var min=parseInt(min);
    if(inform[type]==undefined){
        return false
    }
    for(let obj in inform[type]){//obj返回键名称
        //创建对象时obj要[obj]取出里面的名称,不能直接写
        if(inform[type][obj] < max&&inform[type][obj]> min){//obj是对象属性名称
            arr.push({[obj]:inform[type][obj]});
        }
    }
    
    return arr;//
}
function register(name,email,age){
     for(var obj of userList){
     if(obj.name==name){
        console.log("已经存在")
        return "注册失败"
     }
     }
    var obj={"name":name,"email":email,"age":age};
    userList.push(obj);
       console.log(userList);
    return obj;
}

function edit(newname,newemail,newage){
    var flag=false;//修改判断,真为修改,假为添加
    for(var obj of userList){
    if(obj.name==newname){
        obj.email=newemail;obj.age=newage; obj.name=newname;
        flag=true;
        break; 
      }
}
if(flag){
    console.log(userList);
    console.log("修改成功")
}else{
    var obj={"name":newname,"email":newemail,"age":newage};
    userList.push(obj);
    console.log(userList);
    console.log("添加成功")
}
}
function showlist(){
    return userList;
   }
module.exports={orderlist:inform,
    searchGood:searchGoods,register:register,edit:edit,showlist:showlist

}